home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Acere (Card Game) / AcereÄ.sit / Acereƒ / WellFreeCell.cp < prev    next >
Text File  |  1994-08-25  |  6KB  |  234 lines

  1. // ===========================================================================
  2. //    WellFreeCell.cp                        ⌐1993 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    Class for an object that can draw itself and respond to mouse clicks
  6.  
  7. #ifdef PowerPlant_PCH
  8. #include PowerPlant_PCH
  9. #endif
  10.  
  11. #include "WellFreeCell.h"
  12. #include "CardDeck.h"
  13. #include "AcereApp.h"
  14. #include "CTextDoc.h"
  15. #include <LView.h>
  16. #include <LStream.h>
  17. #include <PP_Messages.h>
  18. #include <UDrawingState.h>
  19.  
  20. extern CTextDoc *theDoc;
  21.  
  22. // ---------------------------------------------------------------------------
  23. //        Ñ CreatePaneStream [static]
  24. // ---------------------------------------------------------------------------
  25. //    Return a new Pane object initialized using data from a Stream
  26.  
  27. WellFreeCell*
  28. WellFreeCell::CreateWellFreeCell(
  29.     LStream    *inStream)
  30. {
  31.     return (new WellFreeCell(inStream));
  32. }
  33.  
  34.  
  35. // ---------------------------------------------------------------------------
  36. //        Ñ WellFreeCell()
  37. // ---------------------------------------------------------------------------
  38. //    Default Constructor
  39.  
  40. WellFreeCell::WellFreeCell()
  41. {
  42.     mPaneID = 0;
  43.     mFrameSize.width = mFrameSize.height = 0;
  44.     mFrameLocation.h = mFrameLocation.v = 0;
  45.     mUserCon = 0;
  46.     
  47.     mFrameBinding.left =
  48.         mFrameBinding.top =
  49.         mFrameBinding.right =
  50.         mFrameBinding.bottom = false;
  51.     
  52.     mVisible = mActive = mEnabled = triState_Latent;
  53.  
  54.     mSuperView = nil;
  55.     
  56.  
  57.     theDoc->theFreeCells[theDoc->currentFreeCell] = this;
  58.     theDoc->currentFreeCell++;
  59.     itsCard.card = kNoCard;
  60.     itsCard.itsOwner = this;
  61. }
  62.  
  63.  
  64. // ---------------------------------------------------------------------------
  65. //        Ñ WellFreeCell(const WellFreeCell&)
  66. // ---------------------------------------------------------------------------
  67. //    Copy Constructor
  68.  
  69. WellFreeCell::WellFreeCell(
  70.     const WellFreeCell    &inOriginal)
  71. {
  72.                                     // Copy members of Original
  73.     mPaneID = inOriginal.mPaneID;
  74.     mFrameSize = inOriginal.mFrameSize;
  75.     mFrameLocation = inOriginal.mFrameLocation;
  76.     mFrameBinding = inOriginal.mFrameBinding;
  77.     mUserCon = inOriginal.mUserCon;
  78.     
  79.     mSuperView = nil;                // Copy is not inside any View
  80.     
  81.                                     // Pane properties. If Original has
  82.                                     //   property ON, Copy is Latent.
  83.     mVisible = inOriginal.mVisible;
  84.     if (mVisible == triState_On) {
  85.         mVisible = triState_Latent;
  86.     }
  87.  
  88.     mActive = inOriginal.mActive;
  89.     if (mActive == triState_On) {
  90.         mActive = triState_Latent;
  91.     }
  92.  
  93.     mEnabled = inOriginal.mEnabled;
  94.     if (mEnabled == triState_On) {
  95.         mEnabled = triState_Latent;
  96.     }
  97.  
  98.     
  99.     theDoc->theFreeCells[theDoc->currentFreeCell] = this;
  100.     theDoc->currentFreeCell++;
  101.     itsCard.card = kNoCard;
  102.     itsCard.itsOwner = this;
  103. }
  104.  
  105.  
  106. // ---------------------------------------------------------------------------
  107. //        Ñ WellFreeCell(SPaneInfo&)
  108. // ---------------------------------------------------------------------------
  109. //    Construct Pane from data in a struct
  110.  
  111. WellFreeCell::WellFreeCell(
  112.     const SPaneInfo    &inPaneInfo)
  113. {
  114.     InitPane(inPaneInfo);
  115. }
  116.  
  117.  
  118. // ---------------------------------------------------------------------------
  119. //        Ñ WellFreeCell(LStream*)
  120. // ---------------------------------------------------------------------------
  121. //    Construct Pane from data in a Stream
  122.  
  123. WellFreeCell::WellFreeCell(
  124.     LStream    *inStream)
  125. {
  126.     SPaneInfo    thePaneInfo;
  127.     inStream->ReadData(&thePaneInfo, sizeof(SPaneInfo));
  128.     InitPane(thePaneInfo);
  129. }
  130.  
  131.  
  132. // ---------------------------------------------------------------------------
  133. //        Ñ InitPane
  134. // ---------------------------------------------------------------------------
  135. //    Initialize Pane from data in a struct
  136.  
  137. void
  138. WellFreeCell::InitPane(
  139.     const SPaneInfo    &inPaneInfo)
  140. {
  141.     mPaneID = inPaneInfo.paneID;
  142.     mFrameSize.width = inPaneInfo.width;
  143.     mFrameSize.height = inPaneInfo.height;
  144.     mUserCon = inPaneInfo.userCon;
  145.     
  146.     mVisible = triState_Off;
  147.     if (inPaneInfo.visible) {
  148.         mVisible = triState_Latent;
  149.     }
  150.  
  151.     mActive = triState_Latent;
  152.  
  153.     mEnabled = triState_Off;
  154.     if (inPaneInfo.enabled) {
  155.         mEnabled = triState_Latent;
  156.     }
  157.     
  158.     mFrameBinding = inPaneInfo.bindings;
  159.     
  160.     mSuperView = nil;
  161.     
  162.     LView    *theSuperView = inPaneInfo.superView;
  163.     if (theSuperView == Default_SuperView) {
  164.         theSuperView = GetDefaultView();
  165.     }
  166.     PutInside(theSuperView);
  167.     if (theSuperView != nil) {
  168.         PlaceInSuperImageAt(inPaneInfo.left, inPaneInfo.top, false);
  169.         Boolean    expandHoriz = (inPaneInfo.width < 0);
  170.         Boolean    expandVert = (inPaneInfo.height < 0);
  171.         if (expandHoriz || expandVert) {
  172.             theSuperView->ExpandSubPane(this, expandHoriz, expandVert);
  173.         }
  174.     }
  175.     
  176.     theDoc->theFreeCells[theDoc->currentFreeCell] = this;
  177.     theDoc->currentFreeCell++;
  178.     itsCard.card = kNoCard;
  179.     itsCard.itsOwner = this;
  180. }
  181.  
  182.  
  183. // ---------------------------------------------------------------------------
  184. //        Ñ ~WellFreeCell
  185. // ---------------------------------------------------------------------------
  186. //    Destructor
  187.  
  188. WellFreeCell::~WellFreeCell()
  189. {
  190.     PutInside(nil);
  191.     
  192.     if (sLastPaneClicked == this) {
  193.         sLastPaneClicked = nil;
  194.     }
  195. }
  196.  
  197.  
  198. // ---------------------------------------------------------------------------
  199. //        Ñ Draw
  200. // ---------------------------------------------------------------------------
  201. //    Try to draw contents of a Pane
  202. //
  203. //    inSuperDrawRgnH specifies, in Port coordinates, the portion of the
  204. //    Pane's SuperView that needs to be drawn. Specify nil to bypass
  205. //    the intersection test.
  206. //    
  207. //    This is a wrapper function which calls DrawSelf if it is proper for
  208. //    the Pane to draw. This means that:
  209. //        > Pane's Visible property is on
  210. //        > Pane can be focused
  211. //        > Pane's Frame is in QuickDraw space
  212. //        > Pane's Frame intersects inSuperDrawRgnH
  213.  
  214. void    WellFreeCell::Draw(RgnHandle    inSuperDrawRgnH)
  215. {
  216.     Rect    frame;
  217.     if ( IsVisible()  &&
  218.          FocusDraw()  &&
  219.          CalcPortFrameRect(frame)  &&
  220.          ((inSuperDrawRgnH == nil) || RectInRgn(&frame, inSuperDrawRgnH)) )
  221.     {
  222.         if (itsCard.card == kNoCard)
  223.         {
  224.             EraseRect(&frame);
  225.             FrameRoundRect(&frame, 20, 20);
  226.         }
  227.         else
  228.         {
  229.             theDeck->DrawCard(&itsCard, frame);
  230.             FrameRoundRect(&frame, 20, 20);
  231.         }
  232.     }
  233. }
  234.